package com.fanbai.score.common.dialog;

import android.content.Context;
import android.content.DialogInterface;
import android.support.v7.app.AlertDialog;

/**
 * Created by Administrator on 2017/3/6.
 *
 * @author lizhipei
 */

public class MyAlertDialog {

    /**
     * 单纯的信息提示框
     * @param activity
     * @param title
     * @param msg
     */
    public void showDialog(Context activity, String title, String msg) {
        try {
            AlertDialog.Builder builder = new AlertDialog.Builder(activity);
            builder.setTitle(title);
            builder.setMessage(msg);
            builder.setPositiveButton("确定", null);
            builder.show();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 带取消的对话框，并监听确认按钮
     * @param activity
     * @param title
     * @param msg
     * @param onClick
     */
    public void showDialog(Context activity, String title, String msg, final OnMyAlertDialogClick onClick) {
        try {
            AlertDialog.Builder builder = new AlertDialog.Builder(activity);
            builder.setTitle(title);
            builder.setMessage(msg);
            builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    onClick.onMyAlertDialogClick(false);
                }
            });
            builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    onClick.onMyAlertDialogClick(true);
                }
            });
            builder.show();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
